package com.soft.sitegenerator.ftp;

import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.UIManager;

public class FtpDroplet {
	private JFrame jFrame = null;

	protected UploadFrame applet;

	public static void ftp(String host, String username, String password,
			String destFolder, String sourceFolder) {
		FtpDroplet application = new FtpDroplet();
		FtpParameters.setFtpParameters(host, username, password, destFolder);
		ArrayList filenames = new ArrayList();
		filenames.add(sourceFolder);
		application.getJFrame(filenames).setVisible(false);
	}

	/**
	 * This method initializes jFrame for Non-Graphic mode
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFrame(ArrayList filenames) {
		if (jFrame == null) {
			String systemLookAndFeelClassName = UIManager
					.getSystemLookAndFeelClassName();
			try {
				UIManager.setLookAndFeel(systemLookAndFeelClassName);
			} catch (Exception e) {
				;
			}

			this.applet = new UploadFrame();

			this.applet.init();

			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setSize(400, 400);
			jFrame.setContentPane(applet.getJContentPane());
			jFrame.setTitle("FTP Project");

			this.applet.getDropHandler().addFiles(filenames);
			FtpUploader upl = new FtpUploader(this.applet);
			Thread uploadThread = new Thread(upl);
			uploadThread.start();

		}
		return jFrame;
	}

}
